import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { title } from 'echarts/lib/theme/dark'

// 同步路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },



  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  //重定向到产品信息页面
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/adminManage/goodsses',
  // },
  {
    path: '/',
    component: Layout,
    name: 'sales',
    redirect: '/sales-report',
    meta: {
      // roles: ['superAdmin'],
      title: '销售报表',
    },
    children: [
        {
          path: 'sales-report',
          component: () => import('@/views/sales-report/index'),
          name: 'sales-report',
          meta: {
            title: '销售报表',
             icon: 'dashboard', affix: true
          }
        },]
  
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   meta: {
  //     roles: ['superAdmin','admin']
  //   },
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       name: 'Dashboard',
  //       meta: { title: '首页', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  // 个人信息
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user', noCache: true }
      }
    ]
  },

]

// 异步路由
export const asyncRoutes = [
  //基础信息
  {
    path: '/adminManage',
    component: Layout,
    meta: {
      roles: ['superAdmin', 'admin'],
      title: '基础信息',
    },
    children: [
      {
        path: 'carousel',
        component: () => import('@/views/carousel/index'),
        name: 'carousel',
        meta: {
          title: '轮播图',
        }
      },
      {
        path: 'goodsses',
        component: () => import('@/views/goodsses/index'),
        name: 'goodsses',
        meta: {
          title: '产品信息',
        }
      },
      {
        path: 'goods-category',
        component: () => import('@/views/goods-category/index'),
        name: 'goods-category',
        meta: {
          title: '产品分类',
        }
      },
      {
        path: 'points',
        component: () => import('@/views/points/index'),
        name: 'points',
        meta: {
          roles: ['superAdmin'],
          title: '积分商品',
        }
      },
      {
        path: 'broadcast',
        component: () => import('@/views/broadcast/index'),
        name: 'broadcast',
        meta: {
          title: '广播管理'
        }
      },
      // {
      //   path: 'costomer',
      //   component: () => import('@/views/costomer/index'),
      //   name: 'costomer',
      //   meta: {
      //     title: '客服',
      //   }
      // },

    ]
  },

  //用户管理
  {
    path: '/tenant',
    component: Layout,
    name: 'tenant',
    meta: {
      roles: ['superAdmin', 'admin'],
      title: '订单管理',
    },
    children: [
      {
        path: 'order-wait',
        component: () => import('@/views/order-wait/index'),
        name: 'order-wait',
        meta: {
          title: '待付款订单',
        }
      },
      {
        path: 'order-deliver',
        component: () => import('@/views/order-deliver/index'),
        name: 'order-deliver',
        meta: {
          title: '待发货订单',
        }
      },

      {
        path: 'order-awiting',
        component: () => import('@/views/order-awiting/index'),
        name: 'order-awiting',
        meta: {
          title: '待收货订单',
        }
      },

      {
        path: 'order-success',
        component: () => import('@/views/order-success/index'),
        name: 'order-success',
        meta: {
          title: '已完成订单',
        }
      },

    ]
  },
  //会员管理
  {
    path: '/memberManagement',
    component: Layout,
    name: 'memberManagement',
    meta: {
      roles: ['superAdmin'],
      title: '会员管理',
    },
    children: [
      {
        path: 'member',
        component: () => import('@/views/member/index'),
        name: 'member',
        meta: {
          title: '会员',
        }
      },
      {
        path: 'integral-allocation',
        component: () => import('@/views/integral-allocation/index'),
        name: 'integral-allocation',
        meta: {
          title: '积分配置',
        }
      }
    ]
  },
  //积分管理
  // {
  //   path: '/point',
  // component: Layout,
  // name: 'point',
  // meta: {
  //   roles: ['superAdmin','admin'],
  //   title: '积分管理',
  // },
  //   children:[
  //     {
  //       path: 'points-management',
  //       component: () => import('@/views/points-management/index.vue'),
  //       name: 'points-management',
  //       meta: {
  //         title: '积分定制',
  //       }
  //     },
  //   ]
  // },
  //退款管理
  {
    path: '/refund',
    component: Layout,
    name: 'refund',
    meta: {
      roles: ['superAdmin', 'admin'],
      title: '退款管理',
    },
    children: [
      {
        path: 'order-refund',
        component: () => import('@/views/order-refund/index'),
        name: 'order-refund',
        meta: {
          title: '待退款订单',
        }
      },
      {
        path: 'order-refunded',
        component: () => import('@/views/order-refunded/index'),
        name: 'order-refunded',
        meta: {
          title: '已退款订单',
        }
      },
    ]
  },
  //报表汇总
  {
    path: '/report',
    component: Layout,
    name: 'report',
    meta: {
      roles: ['superAdmin', 'admin'],
      title: '报表汇总',
    },
    children: [
      {
        path: 'catagory-report',
        component: () => import('@/views/category-report/index'),
        name: 'catagory-report',
        meta: {
          title: '分类统计',
        }
      },
      {
        path: 'detail-report',
        component: () => import('@/views/detail-report/index'),
        name: 'detail-report',
        meta: {
          title: '明细统计',
        }
      },


    ]
  },
  //电子卷管理
  {
    path: '/coupon',
    component: Layout,
    name: 'coupon',
    meta: {
      roles: ['superAdmin'],
      title: '电子券管理',
    },
    children: [
      {
        path: 'coupon-creation',
        component: () => import('@/views/coupon-creation/index'),
        name: 'coupon-creation',
        meta: {
          title: '优惠券制作',
        }
      },
      // {
      //   path: 'coupon-released',
      //   component: () => import('@/views/coupon-released/index'),
      //   name: 'coupon-released',
      //   meta: {
      //     title: '已发布优惠卷',
      //   }
      // },
      {
        path: 'coupon-collection-record',
        component: () => import('@/views/coupon-collection-record/index'),
        name: 'coupon-collection-record',
        meta: {
          roles: ['superAdmin'],
          title: '优惠券使用记录',
        }
      },
    ]
  },

  // 404 页面要在最后引入
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
